PREFIX=/usr/local

CC = gcc
# CFLAGS = -g -Wall -pedantic
CFLAGS = -O1 -Wall -pedantic

#
# Editing past this line not recommended.
#

PROGNAME=serswitch
VERSION = 0.1
DEFVERSION = -DVERSION=\"$(VERSION)\"
SOURCES = serctrl.c serctrl.h main.c
DISTFILES = Makefile AUTHORS ChangeLog INSTALL NEWS  README THANKS TODO COPYING $(SOURCES)
DISTDIR = $(PROGNAME)-$(VERSION)
DISTTGZ = $(DISTDIR).tar.gz

default: all
all: $(PROGNAME)

main.o: main.c serctrl.h
	$(CC) $(CFLAGS) $(DEFVERSION) -c -o main.o main.c

serctrl.o: serctrl.h serctrl.c
	$(CC) $(CFLAGS) -c -o serctrl.o serctrl.c

$(PROGNAME): main.o serctrl.o
	$(CC) $(CFLAGS) -o $(PROGNAME) main.o serctrl.o

clean:
	-rm -f *.o

distclean: clean
	-rm -f $(PROGNAME)
	-rm -f TAGS
	-rm -f *~
	-rm -f $(DISTTGZ)
	-rm -rf $(DISTDIR)

install: $(PROGNAME)
	install -d $(PREFIX)/bin
	install -s -g root -o root -m 4755 $(PROGNAME) $(PREFIX)/bin

uninstall:
	rm $(PREFIX)/bin/$(PROGNAME)

tags:
	-etags $(SOURCES)

ldist: 
	-mkdir $(DISTDIR) ; cd $(DISTDIR) ; \
	for F in $(DISTFILES) ; do ln -s ../"$$F" ; done
	tar czhf $(DISTTGZ) $(DISTDIR)
	-rm -rf $(DISTDIR)

dist: ldist
	-echo -e "\n\n== Package \"$(DISTTGZ)\" created. ==\n\n"

distcheck: ldist
	-tar xzf $(DISTTGZ)
	-cd $(DISTDIR) ; if make all ; then  \
	cd .. ; rm -rf $(DISTDIR) ; \
	echo -e "\n\n== Package \"$(DISTTGZ)\" is OK. ==\n\n" ; rm -rf $(DISTDIR) ; \
	else  \
	cd .. ; rm -rf $(DISTTGZ) $(DISTDIR) ; \
	echo -e "\n\n== ERROR building \"$(DISTDIR)\"!\n\"$(DISTTGZ)\" removed.\n\n" ; \
	fi
